package cn.stylefeng.guns.modular.xlb.controller;

import cn.stylefeng.guns.modular.xlb.pojo.request.XlbRequest;
import cn.stylefeng.guns.modular.xlb.service.XlbService;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 线路表控制器
 *
 * @author zhu
 * @date 2021/10/06 11:08
 */
@RestController
@ApiResource(name = "线路表")
public class XlbController {

    @Resource
    private XlbService xlbService;

    /**
     * 添加
     *
     * @author zhu
     * @date 2021/10/06 11:08
     */
    @PostResource(name = "添加", path = "/xlb/add")
    public ResponseData add(@RequestBody @Validated(XlbRequest.add.class) XlbRequest xlbRequest) {
        xlbService.add(xlbRequest);
        return new SuccessResponseData();
    }

    /**
     * 删除
     *
     * @author zhu
     * @date 2021/10/06 11:08
     */
    @PostResource(name = "删除", path = "/xlb/delete")
    public ResponseData delete(@RequestBody @Validated(XlbRequest.delete.class) XlbRequest xlbRequest) {
        xlbService.del(xlbRequest);
        return new SuccessResponseData();
    }

    /**
     * 编辑
     *
     * @author zhu
     * @date 2021/10/06 11:08
     */
    @PostResource(name = "编辑", path = "/xlb/edit")
    public ResponseData edit(@RequestBody @Validated(XlbRequest.edit.class) XlbRequest xlbRequest) {
        xlbService.edit(xlbRequest);
        return new SuccessResponseData();
    }

    /**
     * 查看详情
     *
     * @author zhu
     * @date 2021/10/06 11:08
     */
    @GetResource(name = "查看详情", path = "/xlb/detail")
    public ResponseData detail(@Validated(XlbRequest.detail.class) XlbRequest xlbRequest) {
        return new SuccessResponseData(xlbService.detail(xlbRequest));
    }

    /**
     * 获取列表
     *
     * @author zhu
     * @date 2021/10/06 11:08
     */
    @GetResource(name = "获取列表", path = "/xlb/list")
    public ResponseData list(XlbRequest xlbRequest) {
        return new SuccessResponseData(xlbService.findList(xlbRequest));
    }

    /**
     * 获取列表（带分页）
     *
     * @author zhu
     * @date 2021/10/06 11:08
     */
    @GetResource(name = "分页查询", path = "/xlb/page")
    public ResponseData page(XlbRequest xlbRequest) {
        return new SuccessResponseData(xlbService.findPage(xlbRequest));
    }

}